<template>
  <view>
    <u-navbar title="首页" :is-back="false"></u-navbar>
    <uni-notice-bar show-icon scrollable text="您有新的信息，请及时查看" v-if="msgNum!=0"/>
    <uni-section title="通知公告" type="line">
      <notice-view :notices="notices" @read="(index)=>{this.notices[index].readStatus=0}"></notice-view>
      <o-empty v-if="notices.length==0"></o-empty>
      <view style="margin: auto;margin-top: 30rpx;padding-bottom:20rpx ">
        <view @click="checkMoreNotice" style="text-align: center;display: block;color: #b2b2b2">查看更多<uni-icons color="#b2b2b2" type="right"/></view></view>
    </uni-section>

<!--    <uni-section title="报修操作" type="line">-->
<!--      <uni-row class="demo-uni-row" gutter="0" width="730">-->
<!--        <uni-col :span="6" :push="4">-->
<!--          <view @click="goRepair">-->
<!--            <image src="/static/icon/homePage/handRepair.png" style="width: 140rpx;height: 140rpx;margin: auto;display: block" mode="scaleToFill"></image>-->
<!--            <text style="display: block;text-align: center">手动报修</text>-->
<!--          </view>-->
<!--        </uni-col>-->
<!--        <uni-col  :span="6" :offset="8">-->
<!--          <view @click="scanRepair">-->
<!--            <image src="/static/icon/homePage/sacnRepair.png" style="width: 140rpx;height: 140rpx;margin: auto;display: block" mode="scaleToFill"></image>-->
<!--            <text style="display: block;text-align: center">扫码报修</text>-->
<!--          </view>-->

<!--        </uni-col>-->
<!--      </uni-row>-->
<!--    </uni-section>-->
    <uni-section title="维修单" type="line">
      <repair-card :repair-data="repairOrders"
                   @evaluate="evaluate"
                   @contact="call"
                   @onlineChat="onlineChat"
                   @notification="notificate"
                   :actions="cardActions"
      ></repair-card>
    </uni-section>

<!--    <view class="fab-content">-->
<!--      <image src="/static/icon/homePage/scan.png" @click="scanRepair" class="fab-button" mode="scaleToFill"></image>-->
<!--      <image src="/static/icon/homePage/hand.png" @click="goRepair" class="fab-button" style="margin-top: 30rpx;" mode="scaleToFill"></image>-->
<!--    </view>-->
  </view>
</template>

<script>
import NoticeView from "../../components/NoticeView";
import {NoticeService} from "../public/Notice/noticeService";
import {RepairOrderService} from "../public/repairApplication/repairOrderService";
import RepairCard from "../../components/RepairCard";
import {UserService} from "../../../api/user";
import OEmpty from "../../../uni_modules/o-empty/components/o-empty/o-empty";

export default {
  components: {OEmpty, RepairCard, NoticeView},
  props:{
    msgNum:{
      default:0,
    }
  },
  data() {
    return {
      list: [
        {
          image: 'https://cdn.uviewui.com/uview/swiper/swiper2.png',
          title: '身无彩凤双飞翼，心有灵犀一点通'
        }, {
          image: 'https://cdn.uviewui.com/uview/swiper/swiper3.png',
          title: '谁念西风独自凉，萧萧黄叶闭疏窗，沉思往事立残阳'
        }],
      serviceList: [
        {
          icon: "../../../static/images/user/homePage/notice.png",
          title: "通知公告",
        },
        {
          icon: "../../../static/images/user/homePage/repair.png",
          title: "我的报修",
        },
        {
          icon: "../../../static/images/user/homePage/complaint.png",
          title: "投诉建议",
        },
        {
          icon: "../../../static/images/user/homePage/customer.png",
          title: "联系客服",
        },
      ],
      cardActions:[
        {
          title:"联系维修员",
          icon:"phone",
          method:"contact",
          showStandard:"currentState",
          value:[1,2]
        },
        // {
        //   title:"在线联系",
        //   icon:"phone",
        //   method:"onlineChat",
        //   showStandard:"currentState",
        //   value:[1,2]
        // },
        {
          title:"催单",
          icon:"notification",
          method:"notification",
          showStandard:"currentState",
          value:[1,2]
        },
        {
          title:"评价",
          icon:"chat",
          method:"evaluate",
          showStandard:"currentState",
          value:[3,4]
        },
      ],
      notices:[
      ],
      repairOrders:[],
      refreshIfNeeded:false,
      refreshNotice:false
    }
  },
  created(){
    console.log("onshowC")
    this.init();
  },
  watch:{
    refreshIfNeeded: {
      handler(newValue, oldValue) {
        if(newValue){
          this.refreshIfNeeded=false;
          this.findRepairOrder();
        }
      },
      deep: true
    },
    refreshNotice: {
      handler(newValue, oldValue) {
        if(newValue){
          this.refreshNotice=false;
          this.findNoticesNotContent();
        }
      },
      deep: true
    },
  },
  methods: {
    onClick(e) {
      console.log(e)
    },
    onlineChat(item){
      uni.navigateTo({
        //保留当前页面，跳转到应用内的某个页面
        url: '/pages/public/message/sendMessage?toUserId='+item.repairmanId+"&toUserName="+item.repairmanName
      })
    },
    actionsClick(text) {
      uni.showToast({
        title: text,
        icon: 'none'
      })
    },
    init(){
      this.findNoticesNotContent()
      this.findRepairOrder()
    },
    //查询我发布的正在进行的维修单
    findRepairOrder(){
      let queryParams={
        currentPage:1,
        pageSize:100,
        filters:{
          repairApplicantId:uni.getStorageSync('userInfo').eid,
          currentState:"0$|$1$|$2"
        },
        orderBys:[
          {
            property: "createDatetime",
            order: "desc"
          }
        ]
      }
      RepairOrderService.findRepairOrders(queryParams).then(res=>{
        // console.log("order",res.data.datas)
        this.repairOrders=res.data.datas;
      })
    },
    findNoticesNotContent(){
      let queryParams={
        currentPage:1,
        pageSize:2,
        filters:{
          userId:uni.getStorageSync('userInfo').eid
        },
        orderBys:[
          {
            property: "createDatetime",
            order: "desc"
          }
        ]
      }
      NoticeService.findNoticesNotContent(queryParams).then(res=>{
        // console.log(res)
        this.notices=res.data.datas
      })
    },
    notificate(item){

      uni.showModal({
        title: '催单提示',
        content: '你确定需要催单吗？',
        success: function (res) {
          if (res.confirm) {
            RepairOrderService.reminder(item).then(res=>{
              if(res.data.code==0){
                this.showToast({
                  title:"催单成功"
                })
              }
            })
          }
        }
      });

    },
    // goRepair(){
    //   // console.log("baoxiu","/pages/normalUser/public/repairApplication/index")
    //   uni.navigateTo({
    //     //保留当前页面，跳转到应用内的某个页面
    //     url: '/pages/normalUser/public/repairApplication/index'
    //   })
    // },
    checkMoreNotice(){
      uni.navigateTo({
        //保留当前页面，跳转到应用内的某个页面
        url: '/pages/normalUser/public/Notice/index'
      })
    },
    evaluate(param){
      console.log("parm",param)
    },
    call(param){
      console.log(param.repairmanPhone)
      uni.makePhoneCall({
        phoneNumber: param.repairmanPhone //仅为示例
      });
    },
    // scanRepair(){
    //   uni.scanCode({
    //     success: function (res) {
    //       console.log('条码类型：' + res.scanType);
    //       console.log('条码内容：' + res.result);
    //       let map=new Map();
    //       res.result.split(",").forEach(item=>{
    //         let items=item.split(":");
    //         map.set(items[0],items[1])
    //       })
    //       if(!map.get("deviceCode")){
    //         uni.showToast({
    //           title: '二维码错误',
    //           icon: 'none'
    //         });
    //         return
    //       }
    //       //跳转页面
    //       uni.navigateTo({
    //         //保留当前页面，跳转到应用内的某个页面
    //         url: '/pages/normalUser/public/repairApplication/index?deviceCode='+map.get("deviceCode")
    //       })
    //     }
    //   });
    // }
  }
}
</script>

<style>
.homepageIcon {
  max-width: 60%;
  margin: auto;
  display: block
}

.title {
  text-align: center;
  display: block;
}

.normalServeItem {
  width: 25%;
  height: 120rpx;
  display: inline-block;
}
.fab-content{
  position: fixed;
  /*background-color: #6a6a6a;*/
  width: 90rpx;
  height: 160rpx;
  z-index: 1000;
  right: 42rpx;
  bottom: 180rpx;
}
.fab-button{
  width: 80%;
  height: 45%;
  margin: auto;
  display: block;
  border-radius: 50%;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}

</style>